package com.pond.pond.controller;

import com.pond.common.core.domain.R;
import com.pond.common.core.web.controller.BaseController;
import com.pond.common.core.web.domain.AjaxResult;
import com.pond.common.core.web.page.TableDataInfo;
import com.pond.pond.domain.PondOrder;
import com.pond.pond.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        return getDataTable(orderService.selectOrderListByUserId());
    }

    /**
     * 查询订单详情
     */
    @GetMapping("/myList")
    public TableDataInfo myList(Long orderId) {
        return getDataTable(orderService.selectOrderItemsListByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @PostMapping("/add")
    public R<Long> add(@RequestBody PondOrder pondOrder) {
        return R.ok(orderService.insertOrder(pondOrder));
    }


    /**
     * 删除订单
     */
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids){
        return toAjax(orderService.deleteOrderByIds(ids));
    }

    /**
     * 删除订单详情
     */
    @DeleteMapping("/deleteItems/{ids}")
    public AjaxResult deleteItems(@PathVariable Long[] ids){
        return toAjax(orderService.deleteOrderItemsByIds(ids));
    }
}
